home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Procedure: addToLayeredTx
- //
- // Description:
- //
- // Add a file texture to a layered texture node.
- // If $layeredTx is specified as an empty string
- // than a new layered texture node is created.
- //
- // Arguments:
- // layeredTx : layered texture to add to
- // newTexture : texture to add
- // killColorLayer : if the right-most layer is a color, replace it.
- // connectAlpha : connect textures alpha up to the layered texture alpha
- //
- // Author : Bernard Kwok
- // Last Updated : 07/18/00
- //
- global proc
- string addToLayeredTx(string $layeredTx, string $newTexture,
- int $blendMode,
- int $killColorLayer, int $connectAlpha)
- {
- if (size($newTexture) == 0)
- error ("No texture name passed to addFileToLayeredTx()");
-
- // Create a new layered texture if none
- if (size($layeredTx) == 0)
- $layeredTx = `shadingNode -asTexture layeredTexture`;
-
- int $idx = `getAttr -s ($layeredTx+".inputs")`;
-
- // If layer to connect to has no input, than overwrite it
- if ($killColorLayer && ($idx > 0))
- {
- int $idx1 = $idx - 1;
- string $connected[] = `listConnections -s 1 ($layeredTx+".inputs["+$idx1+"].color")`;
- if (size($connected) == 0)
- $idx = $idx - 1;
- }
- // Just in case something weird happens...
- if ($idx < 0) $idx = 0;
-
- // Hook up the file texture to the layered texture
- while (catch(
- `connectAttr ($newTexture+".outColor") ($layeredTx+".inputs["+$idx+"].color")`))
- {
- $idx = $idx + 1;
- }
-
- if ($connectAlpha)
- {
- while (catch (`connectAttr ($newTexture+".outAlpha") ($layeredTx+".inputs["+$idx+"].alpha")`))
- {
- $idx = $idx + 1;
- }
- }
- //print ("Final index used = " + $idx + "\n");
-
- // Set the blend mode. Leave it at none, if its the first texture
- if ($idx != 0)
- {
- setAttr ($layeredTx + ".inputs[" + $idx + "].blendMode ") $blendMode;
- }
-
- return $layeredTx;
- }
-
-
-